﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RRRSRoguelike.Managers;
using RRRSRoguelike.Enums;
using RRRSRoguelike.Helpers;
using RRRSRoguelike.Helpers.Visualizer;
using System.Drawing;

namespace RRRSRoguelike.Screens
{
    class ReplayScreen:Screen
    {
        bool YesNo;
        DungeonScreen ds;

        public ReplayScreen(DungeonScreen ds)
        {
        	this.ds = ds;
        	
            PanelList.Add( new Panel(new Point(4, 3),
                    Visualizer.GetScreenWidth() - 9, Visualizer.GetScreenHeight() - 6));  
        }

        /// <summary>
        /// Calls Show and returns true on Yes and false on No.  Oh! That rhymes. neat.
        /// </summary>
        /// <returns></returns>
        public bool ShowYesNo()
        {
            YesNo = false;
            
            Show();

            return YesNo;
        }

        public override void Show()
        {
            Clear();



            foreach (Panel p in PanelList)
            {
                p.Clear();
                p.Draw();
            }

            //prompt user
            PanelList[0].Write(Properties.Strings.Replay + Properties.Strings.YNQuestion);

            bool replay;
            ConsoleKey answer;
            
            //read keyboard
            answer = Console.ReadKey(true).Key;

            //is y pressed?
            replay = answer == ConsoleKey.Y;

            //if y is pressed start game
            if (replay)
            {
                YesNo = true;
                
                PanelList[0].Write(Properties.Strings.Replay +" "+
                                   DungeonManager.Instance.Seed.ToString() +
                                   Properties.Strings.YNQuestion);
                
                if (Console.ReadKey(true).Key == ConsoleKey.Y)
                {
                	ds.SetSeed(DungeonManager.Instance.Seed);
                
                	GameManager.Instance.ScreenStack.Push(ds);
                }	
                else
                {
                	GameManager.Instance.ScreenStack.Push(ds);
                }

            }
            else if (answer != ConsoleKey.N)
            {
                //only n can quit, no accidental quit.
                Show();
            }
            else
            {
            	GameManager.Instance.ScreenStack.Push(new MenuScreen());  
            }
            
            GameManager.Instance.SoundManager.PlaySound(SoundList.Pluck.ToString());
            Clear();
        }
    }
}
